
#include "Camera.h"
#include "FrameBufferHandler.h"

#include <glew.h>
#include <glut.h>

Camera camera;

int	windowWidth	   = 512;
int	windowHeight   = 512;

int textureWidthSmall = 64;
int textureHeightSmall = 64;

GLuint w1 = 128;
GLuint w2 = 64;
GLuint w3 = 32;
GLuint w4 = 16;

GLuint h1 = w1;
GLuint h2 = w2;
GLuint h3 = w3;
GLuint h4 = w4;

GLuint bufferID[10];

FrameBufferHandler frame, frameBright, frameComposed, frameSmallDownSampled, frameSmallBlurred, bright1, blurred1, bright2, blurred2, bright3, blurred3, bright4, blurred4;
FrameBufferHandler depthBuffer;

void initFrameBuffer()
{
	glewInit();

	glGenFramebuffersEXT(10,bufferID);

	depthBuffer.SetBufferID(bufferID[0]);
	depthBuffer.SetUpFBO(TEX,windowWidth,windowHeight);
	frame.SetBufferID(bufferID[1]);
	frame.SetUpFBO(TEX,windowWidth,windowHeight);
	frameBright.SetBufferID(bufferID[1]);
	frameBright.SetUpFBO(TEX,windowWidth,windowHeight);
	frameComposed.SetBufferID(bufferID[1]);
	frameComposed.SetUpFBO(TEX,windowWidth,windowHeight);
	frameSmallDownSampled.SetBufferID(bufferID[2]);
	frameSmallDownSampled.SetUpFBO(TEX,textureWidthSmall,textureHeightSmall);
	frameSmallBlurred.SetBufferID(bufferID[2]);
	frameSmallBlurred.SetUpFBO(TEX,textureWidthSmall,textureHeightSmall);
	bright1.SetBufferID(bufferID[3]);
	bright1.SetUpFBO(TEX,w1,h1);
	blurred1.SetBufferID(bufferID[3]);
	blurred1.SetUpFBO(TEX,w1,h1);
	bright2.SetBufferID(bufferID[4]);
	bright2.SetUpFBO(TEX,w2,h2);
	blurred2.SetBufferID(bufferID[4]);
	blurred2.SetUpFBO(TEX,w2,h2);
	bright3.SetBufferID(bufferID[5]);
	bright3.SetUpFBO(TEX,w3,h3);
	blurred3.SetBufferID(bufferID[5]);
	blurred3.SetUpFBO(TEX,w3,h3);
	bright4.SetBufferID(bufferID[6]);
	bright4.SetUpFBO(TEX,w4,h4);
	blurred4.SetBufferID(bufferID[6]);
	blurred4.SetUpFBO(TEX,w4,h4);
	
}

void init()
{
	glShadeModel(GL_SMOOTH);
	glClearColor(0.8f, 0.4f, 0.5f, 0.5f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	initFrameBuffer();
}

void display()
{

}

void main(int argc, char *argv[])
{

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(windowWidth, windowHeight);

	glutCreateWindow("FLIP");
	

	camera = Camera( 0,0,-2,0,0,1,0,-1,0 );

	init();

	glutDisplayFunc(display);

	glutMainLoop();
}